#!/usr/bin/perl

require "./mailadmin-lib.pl";
my ($k, $i, @vols, @baktime, $mailroot, $alertmsg);

@vols = &get_volumes();
$mailroot = &qmail_dir_get();

if (@vols < 1)
{
    $alertmsg= $text{'msg_no_uservol'};
}

&header($text{'maildir_title'}, "", "mail_edit", 0, 1);

print "<form name=qdform action=maildir_load.cgi method=post onsubmit='return do_submit();'>\n";

print "<table class=mode1 border=0>\n";
print "<tr><td>$text{'maildir_set'}</td>";
print "<td><select name=selvol class=list size=1>\n";
for ($i = 0 ; $i < @vols; $i++)
{
    printf "<option value=\"$vols[$i]\" %s>$text{'path_in_vol'}&nbsp;$vols[$i]\n", ($mailroot =~ /$vols[$i]/) ? "selected" :"";
}
print "</select>\n";
print "</td></tr>";

open (BAKTIME, $config{'back_conf_time'});
@baktime = <BAKTIME>;
close (BAKTIME);

print "<tr><td>$text{'bak_conf'}&nbsp;&nbsp;</td><td>@baktime</td></tr>";

print "</table>\n";

print "<div style='valign:top;width:100%;height:20;overflow:auto'>";
print "</div>\n";
print "<table class=mode1 border=0>\n";

#print "<tr><td width=15%><input name=btn_backup type=submit class=button1 value=\"$text{'btn_backup'}\" onclick=\"return btnsave()\"></td> \n";
print "<tr><td width=15%><input name=btn_loadout type=submit class=button1 value=\"$text{'btn_loadout'}\" onclick=\"return btnloadout()\"></td> \n";
print "<td>$text{'discrp_loadout'}</td></tr>";
print "<tr><td><input type=submit name=btn_loadin class=button1 value=\"$text{'btn_loadin'}\" onclick=\"return btnloadin()\"></td> \n";
print "<td>$text{'discrp_loadin'}</td></tr>";
print "<tr><td><input type=submit name=btn_chdir class=button1 value=\"$text{'btn_chdir'}\" onclick=\"return btnchdir()\"></td> \n";
print "<td>$text{'discrp_chdir'}</td></tr>";


print "</table>";
print "</form>\n";


print <<EOF;
<script>
function do_submit()
{
//    document.forms[0].btn_backup.disabled = true;
//    document.forms[0].btn_load.disabled = true;
    document.forms[0].btn_loadout.disabled = true;
    document.forms[0].btn_loadin.disabled = true;
    document.forms[0].btn_chdir.disabled = true;
}

function btnload()
{
    document.qdform.action="maildir_load.cgi";
}

function btnsave()
{
    document.qdform.action="maildir_save.cgi";
}

function btnloadin()
{
    document.qdform.action="edit_loadin.cgi";
}

function btnloadout()
{
    document.qdform.action="edit_loadout.cgi";
}

function btnchdir()
{
    document.qdform.action="save_chgdir.cgi";
}

</script>
EOF

&footer("/", $text{"index"}, "index.cgi", $text{"back_mailadmin"});

if($alertmsg)
{
	print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
	print "document.forms[0].btn_loadin.disabled = true;\n";
	print "document.forms[0].btn_loadout.disabled = true;\n";
	print "document.forms[0].btn_chdir.disabled = true;\n";
	print "alert(\"$alertmsg\")\n";
	print "</SCRIPT>\n";
}
